package net.sharpf2.api.interfaces;

import net.sharpf2.api.Globals;
import net.sharpf2.api.Methods;
import net.sharpf2.api.game.Interfaces;

/**
 *
 * @author Rick van Biljouw
 */
public class Lobby {
    
    /**
     * Checks if player is in lobby.
     * @return true if player is in lobby, otherwise false.
     */
    public static boolean isInLobby() {
        return Globals.CLIENT.getGamestate() == 7;
    }
    
    /**
     * Clicks the play button.
     */
    public static void play() {
        if (Interfaces.get(Constants.LOBBY_INTERFACE, 215).getContent().getTextureId() == 4671) {
            Interfaces.get(Constants.LOBBY_INTERFACE, Constants.BUTTON_PLAY).getActions().click();
        } else {
            selectPlayerInfo();
            Methods.sleep(500);
            play();
        }
    }
    
    /**
     * Logs the player out from the lobby
     */
    public static void logout() {
        Interfaces.get(Constants.LOBBY_INTERFACE, Constants.BUTTON_LOGOUT).getActions().click();
    }
    
    /**
     * Selects the player info tab
     */
    public static void selectPlayerInfo() {
        Interfaces.get(Constants.LOBBY_INTERFACE, Constants.BUTTON_PLAYER_INFO).getActions().click();
    }
    
    /**
     * Selects the world select tab
     */
    public static void selectWorldSelect() {
        Interfaces.get(Constants.LOBBY_INTERFACE, Constants.BUTTON_WORLDSELECT).getActions().click();
    }    
    
    /**
     * Selects the friends tab
     */
    public static void selectFriends() {
        Interfaces.get(Constants.LOBBY_INTERFACE, Constants.BUTTON_FRIENDS).getActions().click();
    }    
    
    /**
     * Selects the friends chat tab
     */
    public static void selectFriendsChat() {
        Interfaces.get(Constants.LOBBY_INTERFACE, Constants.BUTTON_FRIENDS_CHAT).getActions().click();
    }    
    
    /**
     * Selects the clan chat tab
     */
    public static void selectClanChat() {
        Interfaces.get(Constants.LOBBY_INTERFACE, Constants.BUTTON_CLAN_CHAT).getActions().click();
    }    
    
    /**
     * Selects the options tab
     */
    public static void selectOptions() {
        Interfaces.get(Constants.LOBBY_INTERFACE, Constants.BUTTON_OPTIONS).getActions().click();
    }    
    
    /**
     * Returns the world select interface
     * @return world select interface
     */
    public static WorldSelect getWorldSelect() {
        return new WorldSelect();
    }
    
    /**
     * Class the current world.
     */
    public static class WorldSelect {
        
        public String getSelectedWorld() {
            return Interfaces.get(Constants.WORLD_SELECT_INTERFACE, Constants.TEXT_CURRENT_WORLD).getContent().getText();
        }
        
    }
    
    class Constants {
        public final static int LOBBY_INTERFACE = 906;
        public final static int BUTTON_PLAYER_INFO = 199;
        public final static int BUTTON_WORLDSELECT = 200;
        public final static int BUTTON_FRIENDS = 201;
        public final static int BUTTON_FRIENDS_CHAT = 202;
        public final static int BUTTON_CLAN_CHAT = 203;
        public final static int BUTTON_OPTIONS = 204;
        public final static int BUTTON_LOGOUT = 206; 
        public final static int BUTTON_PLAY = 182;
        
        public final static int WORLD_SELECT_INTERFACE = 910;
        public final static int BUTTON_REFRESH = 6;
        public final static int TEXT_CURRENT_WORLD = 11;
        public final static int LIST_WORLDS = 77;
        public final static int COLUMN_WORLD = 69;
        public final static int COLUMN_PLAYERS = 71;
        public final static int COLUMN_LOCATION_ACTIVITY = 72;
        public final static int COLUMN_TYPE = 74;
        public final static int COLUMN_PING = 76;
        public final static int SCROLLBAR_AREA = 86;
        public final static int SCROLLBAR = 1;
        
    }
    
}
